package com.hc.bank.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import com.hc.bank.util.BaseDao;

public class AccountDao {

	BaseDao dao = new BaseDao();

	public Map<String, Object> findUserLogin(String account, String pwd) {

		String sql = "SELECT id,cardno,balance from account where cardno = ? and `password` = ? and `status` = 1";

		Map<String, Object> map = new HashMap<String, Object>();

		Connection connection = dao.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;

		try {
			ps = connection.prepareStatement(sql);
			ps.setString(1, account);
			ps.setString(2, pwd);

			rs = ps.executeQuery();
			while (rs.next()) {
				map.put("id", rs.getInt("id"));
				map.put("cardno", rs.getString("cardno"));
				map.put("balance", rs.getDouble("balance"));
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dao.closeAll(rs, ps, connection);
		}
		return map;
	}

}
